package com.mes.check.domain;

import java.util.Collection;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.hibernate.annotations.BatchSize;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.ForeignKey;
import org.hibernate.annotations.GenericGenerator;
import org.springframework.context.annotation.Lazy;

import com.mes.common.domain.BasicModel;

@Entity()
@Table(name = "M_CHECKHEADER")
@BatchSize(size = 20)
@Lazy(value = true)
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class CheckBill extends BasicModel implements java.io.Serializable {

	public final static int CHECK_BILLSTATE_CREATED = 0; // 已创建
	public final static int CHECK_BILLSTATE_JUDGED = 2; // 已送审
	public final static int CHECK_BILLSTATE_CLOSED = 10; // 已结案

	@Id
	@GenericGenerator(name = "uniqueId", strategy = "assigned")
	@Column(name = "CHECKUID")
	public String uniqueId;

	@Column(name = "CHECKID", length = 50)
	public String billNumber;

	@Column(name = "MATERIALUSN", length = 50)
	public String materialUid;

	@Column(name = "TASKUID", length = 50)
	public String taskUid;

	@Column(name = "CHECKTYPE", length = 10)
	public String checkBillType;
	
	@Column(name = "CHECKSTATE", length = 10)
	public Integer checkBillState;
	
	@Column(name = "QUALITYSTATE", length = 10)
	public Integer qualityState;

	@Column(name = "SUBMITEMPLOYEEID", length = 50)
	public String submitEmployeeUid;

	@Column(name = "SUBMITDEPTID", length = 50)
	public String submitDeptUid;

	@Column(name = "SUBMITDATE")
	public java.util.Date submitDate;

	@Column(name = "SUBMITQTY", length = 10)
	public Float submitQty;

	@Column(name = "DEFECTQTY", length = 10)
	public Float defectQty;

	@Column(name = "CHECKER", length = 50)
	public String checkerUid;

	@Column(name = "CHECKTIME")
	public java.util.Date checkTime;

	@Column(name = "DEPTID", length = 50)
	public String deptUid;

	@Column(name = "ATTATCHREF", length = 100)
	public String attatchRef;

	@Column(name = "MEASUREBASE", length = 100)
	public String measureBase;

	@Column(name = "SUBMITREASON", length = 100)
	public String submitReason;

	@Column(name = "CHECKERPRINT", length = 50)
	public String checkerPrint;

	@Column(name = "REFCHECKUID", length = 50)
	public String refCheckBillUid;

	@Column(name = "CHECKTASKUID", length = 50)
	public String checkTaskUid;

	@ForeignKey(name = "null")
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "CHECKTASKUID", insertable = false, updatable = false)
	protected CheckTask checkTask;

	@Column(name = "CHECKDEVICEID", length = 50)
	public String checkDeviceUid;

	@Column(name = "APPROVESTATE", length = 10)
	public Integer approveState;

	@Column(name = "APPROVEPERSON", length = 50)
	public String approvePersonUid;

	/** 抽检数 */
	@Column(name = "ACTUALCHECKQTY", length = 10)
	public Float actualCheckQty;

	/** 特性数 */
	@Column(name = "KEYCOUNT", length = 5)
	public Integer keyCount;

	/** 交检次数 */
	@Column(name = "CHECKCOUNT", length = 5)
	public String checkCount;

	/** 自身发现不合格数 */
	@Column(name = "DEFECTQTY_BEFORECHECK", length = 10)
	public Float defectQtyBeforeCheck;

	/** 是否参与一次交检合格率统计 */
	@Column(name = "IS_STATISTIC")
	public Boolean isStatistic;

	@OneToMany(fetch = FetchType.LAZY, mappedBy = "checkBill")
	public List<CheckBillDetail> checkBillDetails;

	public CheckBill() {
		// TODO Auto-generated constructor stub
	}

	@Override
	public String getUuid() {
		// TODO Auto-generated method stub
		return this.uniqueId;
	}

	@Override
	public void setUuid(String uuid) {
		// TODO Auto-generated method stub
		this.uniqueId = uuid;
	}

	/**
	 * Get value of checkUid
	 *
	 * @return checkUid
	 */
	public String getUniqueId() {
		return uniqueId;
	}

	/**
	 * Set value of checkUid
	 *
	 * @param newCheckUid
	 */
	public void setUniqueId(String uniqueId) {
		this.uniqueId = uniqueId;
	}

	/**
	 * Get value of billNumber
	 *
	 * @return billNumber
	 */
	public String getBillNumber() {
		return billNumber;
	}

	/**
	 * Set value of billNumber
	 *
	 * @param billNumber
	 */
	public void setBillNumber(String billNumber) {
		this.billNumber = billNumber;
	}

	/**
	 * Get value of materialUid
	 *
	 * @return materialUid
	 */
	public String getMaterialUid() {
		return materialUid;
	}

	/**
	 * Set value of materialUid
	 *
	 * @param materialUid
	 */
	public void setMaterialUid(String materialUid) {
		this.materialUid = materialUid;
	}

	/**
	 * Get value of taskUid
	 *
	 * @return taskUid
	 */
	public String getTaskUid() {
		return taskUid;
	}

	/**
	 * Set value of taskUid
	 *
	 * @param newTaskUid
	 */
	public void setTaskUid(String newTaskUid) {
		this.taskUid = newTaskUid;
	}

	/**
	 * Get value of checkBillType
	 *
	 * @return checkBillType
	 */
	public String getCheckBillType() {
		return checkBillType;
	}

	/**
	 * Set value of checkBillType
	 *
	 * @param checkBillType
	 */
	public void setCheckBillType(String checkBillType) {
		this.checkBillType = checkBillType;
	}

	/**
	 * Get value of submitEmployeeId
	 *
	 * @return submitEmployeeId
	 */
	public String getSubmitEmployeeUid() {
		return submitEmployeeUid;
	}

	/**
	 * Set value of submitEmployeeId
	 *
	 * @param newSubmitEmployeeId
	 */
	public void setSubmitEmployeeUid(String newSubmitEmployeeUid) {
		this.submitEmployeeUid = newSubmitEmployeeUid;
	}

	/**
	 * Get value of submitDeptId
	 *
	 * @return submitDeptId
	 */
	public String getSubmitDeptUid() {
		return submitDeptUid;
	}

	/**
	 * Set value of submitDeptId
	 *
	 * @param newSubmitDeptId
	 */
	public void setSubmitDeptUid(String newSubmitDeptUid) {
		this.submitDeptUid = newSubmitDeptUid;
	}

	/**
	 * Get value of submitDate
	 *
	 * @return submitDate
	 */
	public java.util.Date getSubmitDate() {
		return submitDate;
	}

	/**
	 * Set value of submitDate
	 *
	 * @param newSubmitDate
	 */
	public void setSubmitDate(java.util.Date newSubmitDate) {
		this.submitDate = newSubmitDate;
	}

	/**
	 * Get value of submitQty
	 *
	 * @return submitQty
	 */
	public Float getSubmitQty() {
		return submitQty;
	}

	/**
	 * Set value of submitQty
	 *
	 * @param newSubmitQty
	 */
	public void setSubmitQty(Float newSubmitQty) {
		this.submitQty = newSubmitQty;
	}

	/**
	 * Get value of defectQty
	 *
	 * @return defectQty
	 */
	public Float getDefectQty() {
		return defectQty;
	}

	/**
	 * Set value of defectQty
	 *
	 * @param newDefectQty
	 */
	public void setDefectQty(Float newDefectQty) {
		this.defectQty = newDefectQty;
	}

	/**
	 * Get value of checkerUid
	 *
	 * @return checkerUid
	 */
	public String getCheckerUid() {
		return checkerUid;
	}

	/**
	 * Set value of checkerUid
	 *
	 * @param checkerUid
	 */
	public void setCheckerUid(String checkerUid) {
		this.checkerUid = checkerUid;
	}

	/**
	 * Get value of checkTime
	 *
	 * @return checkTime
	 */
	public java.util.Date getCheckTime() {
		return checkTime;
	}

	/**
	 * Set value of checkTime
	 *
	 * @param newCheckTime
	 */
	public void setCheckTime(java.util.Date newCheckTime) {
		this.checkTime = newCheckTime;
	}

	/**
	 * Get value of deptUid
	 *
	 * @return deptUid
	 */
	public String getDeptUid() {
		return deptUid;
	}

	/**
	 * Set value of deptUid
	 *
	 * @param deptUid
	 */
	public void setDeptUid(String deptUid) {
		this.deptUid = deptUid;
	}

	/**
	 * Get value of attatchRef
	 *
	 * @return attatchRef
	 */
	public String getAttatchRef() {
		return attatchRef;
	}

	/**
	 * Set value of attatchRef
	 *
	 * @param newAttatchRef
	 */
	public void setAttatchRef(String newAttatchRef) {
		this.attatchRef = newAttatchRef;
	}

	// /**
	// * Get value of creator
	// *
	// * @return creator
	// */
	// public String getCreator()
	// {
	// return creator;
	// }
	//
	// /**
	// * Set value of creator
	// *
	// * @param newCreator
	// */
	// public void setCreator(String newCreator)
	// {
	// this.creator = newCreator;
	// }

	// /**
	// * Get value of createTime
	// *
	// * @return createTime
	// */
	// public java.util.Date getCreateTime()
	// {
	// return createTime;
	// }
	//
	// /**
	// * Set value of createTime
	// *
	// * @param newCreateTime
	// */
	// public void setCreateTime(java.util.Date newCreateTime)
	// {
	// this.createTime = newCreateTime;
	// }

	/**
	 * Get value of notes
	 *
	 * @return notes
	 */
	public String getNotes() {
		return notes;
	}

	/**
	 * Set value of notes
	 *
	 * @param newNotes
	 */
	public void setNotes(String newNotes) {
		this.notes = newNotes;
	}

	/**
	 * Get value of measureBase
	 *
	 * @return measureBase
	 */
	public String getMeasureBase() {
		return measureBase;
	}

	/**
	 * Set value of measureBase
	 *
	 * @param newMeasureBase
	 */
	public void setMeasureBase(String newMeasureBase) {
		this.measureBase = newMeasureBase;
	}

	/**
	 * Get value of submitReason
	 *
	 * @return submitReason
	 */
	public String getSubmitReason() {
		return submitReason;
	}

	/**
	 * Set value of submitReason
	 *
	 * @param newSubmitReason
	 */
	public void setSubmitReason(String newSubmitReason) {
		this.submitReason = newSubmitReason;
	}

	/**
	 * Get value of checkBillState
	 *
	 * @return checkBillState
	 */
	public Integer getCheckBillState() {
		return checkBillState;
	}

	/**
	 * Set value of checkBillState
	 *
	 * @param checkBillState
	 */
	public void setCheckBillState(Integer checkBillState) {
		this.checkBillState = checkBillState;
	}

	/**
	 * Get value of qualityState
	 *
	 * @return qualityState
	 */
	public Integer getQualityState() {
		return qualityState;
	}

	/**
	 * Set value of qualityState
	 *
	 * @param newQualityState
	 */
	public void setQualityState(Integer newQualityState) {
		this.qualityState = newQualityState;
	}

	/**
	 * Get value of checkerPrint
	 *
	 * @return checkerPrint
	 */
	public String getCheckerPrint() {
		return checkerPrint;
	}

	/**
	 * Set value of checkerPrint
	 *
	 * @param newCheckerPrint
	 */
	public void setCheckerPrint(String newCheckerPrint) {
		this.checkerPrint = newCheckerPrint;
	}

	/**
	 * Get value of refCheckBillUid
	 *
	 * @return refCheckBillUid
	 */
	public String getRefCheckBillUid() {
		return refCheckBillUid;
	}

	/**
	 * Set value of refCheckBillUid
	 *
	 * @param refCheckBillUid
	 */
	public void setRefCheckBillUid(String refCheckBillUid) {
		this.refCheckBillUid = refCheckBillUid;
	}

	/**
	 * Get value of checkTaskUid
	 *
	 * @return checkTaskUid
	 */
	public String getCheckTaskUid() {
		return checkTaskUid;
	}

	/**
	 * Set value of checkTaskUid
	 *
	 * @param newCheckTaskUid
	 */
	public void setCheckTaskUid(String newCheckTaskUid) {
		this.checkTaskUid = newCheckTaskUid;
	}

	/**
	 * Get value of checkDeviceUid
	 *
	 * @return checkDeviceUid
	 */
	public String getCheckDeviceUid() {
		return checkDeviceUid;
	}

	/**
	 * Set value of checkDeviceUid
	 *
	 * @param newCheckDeviceUid
	 */
	public void setCheckDeviceUid(String newCheckDeviceUid) {
		this.checkDeviceUid = newCheckDeviceUid;
	}

	/**
	 * Get value of approveState
	 *
	 * @return approveState
	 */
	public Integer getApproveState() {
		return approveState;
	}

	/**
	 * Set value of approveState
	 *
	 * @param newApproveState
	 */
	public void setApproveState(Integer newApproveState) {
		this.approveState = newApproveState;
	}

	/**
	 * Get value of approvePersonUid
	 *
	 * @return approvePersonUid
	 */
	public String getApprovePersonUid() {
		return approvePersonUid;
	}

	/**
	 * Set value of approvePersonUid
	 *
	 * @param newApprovePersonUid
	 */
	public void setApprovePersonUid(String newApprovePersonUid) {
		this.approvePersonUid = newApprovePersonUid;
	}

	/**
	 * Get value of actualCheckQty
	 *
	 * @return actualCheckQty
	 */
	public Float getActualCheckQty() {
		return actualCheckQty;
	}

	/**
	 * Set value of actualCheckQty
	 *
	 * @param newActualCheckQty
	 */
	public void setActualCheckQty(Float newActualCheckQty) {
		this.actualCheckQty = newActualCheckQty;
	}

	/**
	 * Get value of keyCount
	 *
	 * @return keyCount
	 */
	public Integer getKeyCount() {
		return keyCount;
	}

	/**
	 * Set value of keyCount
	 *
	 * @param newKeyCount
	 */
	public void setKeyCount(Integer newKeyCount) {
		this.keyCount = newKeyCount;
	}

	/**
	 * Get value of checkCount
	 *
	 * @return checkCount
	 */
	public String getCheckCount() {
		return checkCount;
	}

	/**
	 * Set value of checkCount
	 *
	 * @param newCheckCount
	 */
	public void setCheckCount(String newCheckCount) {
		this.checkCount = newCheckCount;
	}

	/**
	 * Get value of defectQtyBeforeCheck
	 *
	 * @return defectQtyBeforeCheck
	 */
	public Float getDefectQtyBeforeCheck() {
		return defectQtyBeforeCheck;
	}

	/**
	 * Set value of defectQtyBeforeCheck
	 *
	 * @param newDefectQtyBeforeCheck
	 */
	public void setDefectQtyBeforeCheck(Float newDefectQtyBeforeCheck) {
		this.defectQtyBeforeCheck = newDefectQtyBeforeCheck;
	}

	/**
	 * Get value of isStatistic
	 *
	 * @return isStatistic
	 */
	public Boolean getIsStatistic() {
		return isStatistic;
	}

	/**
	 * Set value of isStatistic
	 *
	 * @param newIsStatistic
	 */
	public void setIsStatistic(Boolean newIsStatistic) {
		this.isStatistic = newIsStatistic;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see Object#equals(Object)
	 */
	public boolean equals(Object other) {

		if (other == null)
			return false;

		if (other == this)
			return true;

		if (!(other instanceof CheckBill))
			return false;

		CheckBill cast = (CheckBill) other;

		if (this.uniqueId == null ? cast.getUniqueId() != this.uniqueId : !this.uniqueId.equals(cast.getUniqueId()))
			return false;

		return true;
	}

	public CheckTask getCheckTask() {
		return checkTask;
	}

	public void setCheckTask(CheckTask checkTask) {
		this.checkTask = checkTask;
	}

	public List<CheckBillDetail> getCheckBillDetails() {
		return checkBillDetails;
	}

	public void setCheckBillDetails(List<CheckBillDetail> checkBillDetails) {
		this.checkBillDetails = checkBillDetails;
	}

}